﻿
namespace SADev.SharePointHolidayLoader
{
    using System;
    using System.Collections.Generic;


    class HolidayList : IEnumerable<Holiday>
    {
        private readonly IList<Holiday> holidays = new List<Holiday>();

        public IEnumerator<Holiday> GetEnumerator()
        {
            return new HolidayListEnumerator(holidays);
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return new HolidayListEnumerator(holidays);
        }

        private class HolidayListEnumerator : IEnumerator<Holiday>
        {
            private readonly IList<Holiday> holidays;
            private int position = -1;

            public HolidayListEnumerator(IList<Holiday> holidays)
            {                
                this.holidays = holidays;
            }
            public Holiday Current
            {
                get 
                {
                    return holidays[position];
                }
            }

            public void Dispose()
            {
                // not applicable
            }

            object System.Collections.IEnumerator.Current
            {
                get 
                {
                    return holidays[position];
                }
            }

            public bool MoveNext()
            {
                position++;
                return position < holidays.Count;
            }

            public void Reset()
            {
                position = -1;
            }
        }


        internal void Add(string name, DateTime date)
        {
            holidays.Add(new Holiday(name, date));
        }
    }
}
